<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录修改</title>
    <script src="ajax.js"></script>
    <script src="common.js"></script>
    <script src="jquery-3.4.1.js"></script>

</head>
<body>
<div>
    <input type="hidden" id="id">
    <div>
        <label>
            名字：<input type="text" id="name">
        </label>
    </div>
    <div>
        <label>
            密码：<input type="text" id="password">
        </label>
    </div>
    <div>
        <button id="changeClick">修改</button>
    </div>
</div>
<script>
    window.onload=function () {
        let formData = new FormData();
        let id = GetQueryString("id");
        formData.append("id", id);
        function updateInput(data) {
            if (data.code == "200") {
                //获取Data里的参数
                let deback = data.data;
                //获取每行文本的值
               $("#name").value =deback.name;
                $("#password").value = deback.password;
            }else{
                //调用后台错误信息
                alert(data.msg);
            }
        }
        //调用ajax get.php，传参 定义好的formData和定义好的回调函数；
        ajax("http://120.79.234.76:8091/login/get.php", "POST", formData, updateInput);
    }
    let id = getQueryStringByName("id");
    if (!id) {
        location.href = "/debackAdd.html"
    }
    $("#id").value=id;
    function changeRes(jsonObj) {
        alert("修改成功");
        window.location.href = "/debackList.html"
    }
    $("#changeClick").click(function (e) {
        let nameId = $("#name").value;
        let passwordId = $("#password").value;
        let formData = new FormData();
        $(formData).append("id", id);
        $(formData).append("name", nameId);
        $(formData).append("password", passwordId);
        ajax("http://120.79.234.76:8091/login/update.php", "POST", formData, changeRes);

    });
</script>
</body>
</html>